import 'package:flame/components/component.dart';
import 'package:flutter/material.dart';
import 'package:flutter/painting.dart';
import 'package:hello_flutter/demo/game/game_controller.dart';

class StartTxT extends Component {
  final GameController controller;
  TextPainter textPainter;
  Offset position;

  StartTxT(this.controller) {
    textPainter = TextPainter(
      textAlign: TextAlign.center,
      textDirection: TextDirection.ltr,
    );
    position = Offset.zero;
  }
  @override
  void render(Canvas canvas) {
    textPainter.paint(canvas, position);
  }

  @override
  void update(double time) {
    textPainter.text = TextSpan(
      text: '开始游戏🎮',
      style: TextStyle(color: Colors.black, fontSize: 56),
    );
    textPainter.layout();
    position = Offset(
      (controller.screenSize.width / 2) - (textPainter.width / 2),
      (controller.screenSize.height * 0.7) - (textPainter.height / 2),
    );
  }
}
